<%@ page import="entity.User" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %><%--
  Created by IntelliJ IDEA.
  User: 石小俊
  Date: 2024/11/14
  Time: 18:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>EL表达式</title>
</head>
<body>
<%
    // 模拟数据
    pageContext.setAttribute("msg", "Hello pageContext");
    request.setAttribute("msg", "Hello request");
    session.setAttribute("msg", "Hello session");
    application.setAttribute("msg", "Hello application");

    User user = new User(1, "admin", "123456", "13812345678", "江苏-南京");
    User user2 = new User(2, "tom", "123456", "13812345678", "江苏-南京");
    User user3 = new User(3, "jack", "123456", "13812345678", "江苏-南京");
    request.setAttribute("user", user);

    List<User> list = new ArrayList<>();
    list.add(user);
    list.add(user2);
    list.add(user3);
    request.setAttribute("list", list);

    Map<String, User> map = new HashMap<>();
    map.put("u1", user);
    map.put("u2", user2);
    map.put("u3", user3);
    request.setAttribute("map", map);
%>
<h2>访问作用域</h2>
pageContext:${pageScope.msg}<br>
request:${requestScope.msg}<br>
session:${sessionScope.msg}<br>
application:${applicationScope.msg}<br>
msg:${msg}
<h2>获取应用名</h2>
应用名:<%=request.getContextPath()%><br>
应用名:${pageContext.request.contextPath}<br>
<h2>访问对象</h2>
${user.id}--${user.username}--${user.password}--${user.phone}--${user.address}
<h2>访问List集合</h2>
${list[0].id}--${list[0].username}<br>
${list[1].id}--${list[1].username}<br>
${list[2].id}--${list[2].username}<br>
<h2>访问Map集合</h2>
${map.u1.id}--${map.u1.username}<br>
${map['u2'].id}--${map['u2'].username}<br>

<h2>运算</h2>
${3+2}<br>
${3-2}<br>
${3*2}<br>
${3/2}<br>
${3%2}<br>
${1 == 1}<br>
${3 > 2}<br>
${1 == "1"}<br>
${3 > 2 and 2 > 3}<br>
${3 > 2 or 2 > 3}<br>
${1 eq "1"}<br>
${3 > 2 ? "3比2大" : "3比2小"}<br>
${empty user}<br>

</body>
</html>
